//
//  PersonViewController.m
//  A手工客
//
//  Created by 萌萌的小坤坤 on 16/6/13.
//  Copyright © 2016年 冷坤. All rights reserved.
//

#import "PersonViewController.h"
#import "ProjectTabView.h"
#import "ProjectModel.h"
#import "AFNetworking.h"
#define PROJECTNET @"http://m.shougongke.com/index.php?c=Course&a=topicList&tag_id=53&vid=18"
@interface PersonViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic ,retain) UITableView *tabView;
@property (nonatomic ,retain) NSMutableArray *arrProject;

@end

@implementation PersonViewController
- (NSMutableArray *)arrProject{
    if (!_arrProject) {
        self.arrProject = [NSMutableArray array];
    }
    return _arrProject;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getProjectUrl];
    [self creatTabView];

}
- (void)creatTabView{
    self.tabView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 375, 667) style:0];
    self.tabView.delegate = self;
    self.tabView.dataSource = self;
    
    [self.view addSubview:self.tabView];
    [_tabView release];
}

- (void)getProjectUrl{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/css",@"text/plain", @"application/javascript",@"image/jpeg", @"text/vnd.wap.wml", nil];
    
    [manager GET:PROJECTNET parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSMutableArray *arr = responseObject[@"data"];
        for (NSDictionary *data in arr) {
            ProjectModel *model = [ProjectModel projectModelWithDic:data];
            
            [self.arrProject addObject:model];
            
        }
        
        [self.tabView reloadData];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        NSLog(@"%@",error);
    }];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 667 / 3.5 + 20;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.arrProject.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *ID = @"cell";
    
    ProjectTabView *projectTab = [tableView dequeueReusableCellWithIdentifier:ID];
    if (projectTab == nil) {
        projectTab = [[ProjectTabView alloc]initWithStyle:1 reuseIdentifier:ID];
        //        videoTab.backgroundColor = COLORS;
        
        
    }
    ProjectModel *models = self.arrProject[indexPath.section];
    projectTab.model = models;
    
    return projectTab;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
